package org.example.quartz.task;

import cn.hutool.db.Entity;
import cn.hutool.db.Session;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.quartz.service.LogService;
import org.example.quartz.service.OrgService;
import org.example.quartz.service.UtilService;
import org.example.quartz.util.DataSourceUtil;
import org.quartz.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Component
// 再Job被执行结束后，将会更新JobDataMap，这样下次Job执行后悔使用新的值而不是初始值
@PersistJobDataAfterExecution
// 同一时间将只有一个Job实例被执行，为了避免并发问题导致数据紊乱，建议这两个注解一起使用
@DisallowConcurrentExecution
public class GLQuartz implements QuartzTaskJob {
    Map<String, Object> gsMap = DataSourceUtil.getGS();
    //全局接口配置
    String IP = (String) gsMap.get("IP");
    String PORT = (String) gsMap.get("PORT");
    String ECC = (String) gsMap.get("ECC");
    String Bearer = (String) gsMap.get("Bearer");

    //日志
    LogService loginfo = SpringUtil.getBean(LogService.class);
    //orgService
    OrgService orgService = SpringUtil.getBean(OrgService.class);
    //orgService
    UtilService utilService = SpringUtil.getBean(UtilService.class);
    /**
     * 凭证接口
     * 接口地址：GSCloud文档3.13
     * http://ip:port/api/jg/fiaccbddata/v1.0/fiaccinterface/insertPzMidTable
     **/
    @SneakyThrows
    @Override
    public void execute(JobExecutionContext context) {
        //传入变量 lastTime 最后抓取时间
        //链接BIP数据库，查询出需要同步的数据，根据TS时间进行判断。
        //TS从中间库表获取到最后一次更新时间，根据此时间进行增量查询推送；
        //中间库日志表记录推送日志，成功、失败、返回信息等（备查）
        //中间库记录最后推送数据的时间，根据时间进行下次查询的条件；
        String methodName = "GLQuartz";
        JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
        //1、查询时间
        String ts = utilService.getTs(methodName, jdbcTemplate);
        String orgStr = utilService.getGSOrgStr(jdbcTemplate);
        //2、根据ts时间戳，查询中间库gl_detail表数据，取100凭证号，定义一个批次，推送成功后，回写100个凭证的状态；
        String selectSQL = "SELECT\n" +
                "\tgl.ID,\n" +
                "\torg.gsztCode,\n" +
                "\tgl.ACCDOCCODE,\n" +
                "\tDATE_FORMAT(gl.ACCDOCDATE, '%Y%m%d') as ACCDOCDATE,\n" +
                "\tgl.ACCDOCTYPECODE,\n" +
                "\tgl.PERIODCODE,\n" +
                "\tgl.NUMBEROFATTCH,\n" +
                "\tgl.YEAR,\n" +
                "\tgl.MAKERCODE,\n" +
                "\tgl.OPERATORCODE,\n" +
                "\tgl.SECRETLEVEL,\n" +
                "\tgl.APPROVERCODE,\n" +
                "\tgl.AUDITORCODE,\n" +
                "\tgl.BOOKERCODE,\n" +
                "\tgl.CASHIERCODE,\n" +
                "\tgl.ACCMANAGERCODE,\n" +
                "\tgl.ISAUDIT,\n" +
                "\tgl.ISBOOK,\n" +
                "\tgl.ISVOID,\n" +
                "\tgl.ISAPPROVED,\n" +
                "\tgl.EXTERNALDOC,\n" +
                "\tgl.ISREADYONLY,\n" +
                "\tgl.CREATOR,\n" +
                "\tgl.CREATETIME,\n" +
                "\tgl.LASTMODIFIER,\n" +
                "\tgl.LASTMODIFIEDTIME,\n" +
                "\tgl.SUMMARY,\n" +
                "\tACCENTRYCODE,\n" +
                "\tgl.ACCTITLECODE,\n" +
                "\tgl.DOCENTRYAMOUNT,\n" +
                "\t(CASE WHEN gl.LENDINGDIRECTION = '借' THEN '1' ELSE '2' END) as  LENDINGDIRECTION,\n" +
                "\tgl.DEPTID,\n" +
                "\tgl.RELATEDORGID,\n" +
                "\tgl.ACCEMPLOYEEID,\n" +
                "\tgl.FOREIGNCURRENCYID,\n" +
                "\tgl.QUANTITY,\n" +
                "\tgl.UNITPRICE,\n" +
                "\tgl.FOREIGNCURRENCY,\n" +
                "\tgl.EXCHANGERATE,\n" +
                "\tgl.ANCILLARYAMOUNT,\n" +
                "\tgl.BIZDATE,\n" +
                "\tgl.BIZCODE,\n" +
                "\tgl.OPERATOR,\n" +
                "\tgl.SJ,\n" +
                "\tgl.SM,\n" +
                "\tgl.SETTLEMENT,\n" +
                "\tgl.SETTLEMENTNUMBER,\n" +
                "\tgl.APPLICATION,\n" +
                "\tgl.SETTLEMENTDATE,\n" +
                "\tgl.CASHPROJECT,\n" +
                "\tgl.SPECATEID,\n" +
                "\tgl.BILLNUMBER,\n" +
                "\tgl.DATASTAUS,\n" +
                "\tgl.ISIMPORTED,\n" +
                "\tgl.FAILREASON,\n" +
                "\tCONCAT(org.gsztCode, UNIX_TIMESTAMP(NOW())) as BATCHNO,\n" +
                "\tgl.REFERENCEID,\n" +
                "\tgl.LYPZID,\n" +
                "\tgl.FZCODE,\n" +
                "\tgl.TS,\n" +
                "\tgl.GSSTATUS,\n" +
                "\tgl.RETURNMSG," +
                "\tgl.ASSID," +
                "\tgl.YYZTCODE \n" +
                "FROM\n" +
                "\tgl_detail gl\n" +
                "left join \n" +
                "\tyy_org_orgs org on gl.orgcode = org.yyztCode\n" +
                "WHERE \n" +
                "  gl.LYPZID IN (SELECT LYPZID from gs_push_100)";
        //查询数据，根据数据结果推送给GS浪潮
        Session oracleSession = DataSourceUtil.getOracleSession();
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(selectSQL);
        //拼装数据，推送给浪潮
        String ids = "";
        //批次号
        String BATCHNO = "";
        if(maps.size()>0){
            Map<String, List<Map<String, Object>>> voucherid = maps.stream().collect(Collectors.groupingBy(i -> i.get("ACCDOCCODE")+","+i.get("PERIODCODE")+","+i.get("YEAR")));
            String GsJson = "";
            String logTS="";
            for (Map.Entry<String, List<Map<String, Object>>> objectListEntry : voucherid.entrySet()) {

                //部门
                String DEPTID = "";
                //RELATEDORGID	往来单位编号
                String RELATEDORGID = "";
                //ACCEMPLOYEEID	核算人员编号
                String ACCEMPLOYEEID = "";
                List<Map<String, Object>> value = objectListEntry.getValue();
                GsJson += "[";
                for (Map<String, Object> gSmap : value) {
                    //查询辅助核算项
                    //获取ID
                    String ASSID = (String) gSmap.get("ASSID");
                    //根据ID查询
                    String FZSQL = "SELECT\n" +
                            "ASSID,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,F25,F26,F27,F28,F29,F30,'' AS F31,'' AS F32,'' AS F33,'' AS F34,'' AS F35,'' AS F36,'' AS F37,'' AS F38,'' AS F39,'' AS F40,'' AS F41,'' AS F42,'' AS F43,'' AS F44,'' AS F45,'' AS F46,'' AS F47,'' AS F48,'' AS F49,'' AS F50,'' AS F51,'' AS F52,'' AS F53,'' AS F54,'' AS F55,'' AS F56,'' AS F57,'' AS F58,'' AS F59,'' AS F60 \n" +
                            "FROM\n" +
                            "GL_DOCFREE1 free \n" +
                            "WHERE\n" +
                            "DR = '0' \n" +
                            "AND ASSID = 'ASSID' \n" +
                            "UNION\n" +
                            "SELECT\n" +
                            "ASSID,'' AS F1,'' AS F2,'' AS F3,'' AS F4,'' AS F5,'' AS F6,'' AS F7,'' AS F8,'' AS F9,'' AS F10,'' AS F11,'' AS F12,'' AS F13,'' AS F14,'' AS F15,'' AS F16,'' AS F17,'' AS F18,'' AS F19,'' AS F20,'' AS F21,'' AS F22,'' AS F23,'' AS F24,'' AS F25,'' AS F26,'' AS F27,'' AS F28,'' AS F29,'' AS F30,F31,F32,F33,F34,F35,F36,F37,F38,F39,F40,F41,F42,F43,F44,F45,F46,F47,F48,F49,F50,F51,F52,F53,F54,F55,F56,F57,F58,F59,F60 \n" +
                            "FROM\n" +
                            "GL_DOCFREE2 free \n" +
                            "WHERE\n" +
                            "DR = '0' \n" +
                            "AND ASSID = '"+ASSID+"'";
                    List<Entity> fzQuery = oracleSession.query(FZSQL);
                    String ISHAVEFZ = "0";
                    if (fzQuery.size() > 0) {
                        ISHAVEFZ = "1";
                        for (Map<String, Object> fzmap : fzQuery) {
                            //部门赋值
                            String yynumSQL = "SELECT CAST(NUM AS CHAR) AS NUM,TABLENAME,TABLEKEY,CODEKEY,NAMEKEY FROM FREEMAP WHERE istrue = 'DEPT'";
                            List<Map<String, Object>> deptMaps = jdbcTemplate.queryForList(yynumSQL);
                            System.out.println("部门"+deptMaps.size());
                            String num = (String) deptMaps.get(0).get("NUM");
                            //判断num对应的辅助核算是否有值，如果有值，将pk转换成code
                            String deptKey = "F" + num;
                            String deptPK = (String) fzmap.get(deptKey);
                            if(!deptPK.equals("NN/A")&&!("").equals(deptPK)&&!deptPK.isEmpty()){
                                //转换code
                                String pkToCode = "SELECT " + deptMaps.get(0).get("CODEKEY") + " AS CODE FROM " + deptMaps.get(0).get("TABLENAME") + " WHERE " + deptMaps.get(0).get("TABLEKEY") + " ='" + deptPK + "'";
                                //DEPTID	核算部门编号
                                List<Entity> DEPTCODE = oracleSession.query(pkToCode);
                                DEPTID = gSmap.get("YYZTCODE")+(String) DEPTCODE.get(0).get("CODE");
                            }
                            //往来单位赋值//RELATEDORGID	往来单位编号
                            String wlnumSQL = "SELECT CAST(NUM AS CHAR) AS NUM,TABLENAME,TABLEKEY,CODEKEY,NAMEKEY FROM FREEMAP WHERE istrue = 'CANDS'";
                            List<Map<String, Object>> wlMaps = jdbcTemplate.queryForList(wlnumSQL);
                            System.out.println("往来"+wlMaps.size());
                            String wlnum = (String) wlMaps.get(0).get("NUM");
                            //判断num对应的辅助核算是否有值，如果有值，将pk转换成code
                            String wlKey = "F" + wlnum;
                            String wlPK = (String) fzmap.get(wlKey);
                            if(!wlPK.equals("NN/A")&&!("").equals(wlPK)&&!wlPK.isEmpty()) {
                                //转换code
                                String wlpkToCode = "SELECT " + wlMaps.get(0).get("CODEKEY") + " AS CODE FROM " + wlMaps.get(0).get("TABLENAME") + " WHERE " + wlMaps.get(0).get("TABLEKEY") + " ='" + wlPK + "'";
                                //DEPTID	核算部门编号
                                List<Entity> WLCODE = oracleSession.query(wlpkToCode);
                                RELATEDORGID = "03"+gSmap.get("YYZTCODE")+(String) WLCODE.get(0).get("CODE");
                            }
                            //人员赋值ACCEMPLOYEEID	核算人员编号
                            String rynumSQL = "SELECT CAST(NUM AS CHAR) AS NUM,TABLENAME,TABLEKEY,CODEKEY,NAMEKEY FROM FREEMAP WHERE istrue = 'PERSON'";
                            List<Map<String, Object>> ryMaps = jdbcTemplate.queryForList(rynumSQL);
                            System.out.println("人员"+wlMaps.size());
                            String rynum = (String) ryMaps.get(0).get("NUM");
                            //判断num对应的辅助核算是否有值，如果有值，将pk转换成code
                            String ryKey = "F" + rynum;
                            String ryPK = (String) fzmap.get(ryKey);
                            if(!ryPK.equals("NN/A")&&!("").equals(ryPK)&&!ryPK.isEmpty()) {
                                //转换code
                                String rypkToCode = "SELECT " + ryMaps.get(0).get("CODEKEY") + " AS CODE FROM " + ryMaps.get(0).get("TABLENAME") + " WHERE " + ryMaps.get(0).get("TABLEKEY") + " ='" + ryPK + "'";
                                //DEPTID	核算部门编号
                                List<Entity> RYCODE = oracleSession.query(rypkToCode);
                                ACCEMPLOYEEID = gSmap.get("YYZTCODE")+(String) RYCODE.get(0).get("CODE");
                            }
                        }
                    }
                    ids += "'"+gSmap.get("ID")+"',";
                    BATCHNO = (String) gSmap.get("BATCHNO");
                    GsJson += "{" +
                            "\"ID\": \"" + gSmap.get("ID") + "\",\n" +
                            "\"ORGCODE\": \"" + gSmap.get("gsztCode") + "\",\n" +
                            "\"ACCDOCCODE\": \"" + gSmap.get("ACCDOCCODE") + "\",\n" +
                            "\"ACCDOCDATE\": \"" + gSmap.get("ACCDOCDATE") + "\",\n" +
                            "\"ACCDOCTYPECODE\": \"" + gSmap.get("ACCDOCTYPECODE") + "\",\n" +
                            "\"PERIODCODE\": \"" + gSmap.get("PERIODCODE") + "\",\n" +
                            "\"NUMBEROFATTCH\": \"" + gSmap.get("NUMBEROFATTCH") + "\",\n" +
                            "\"YEAR\": \"" + gSmap.get("YEAR") + "\",\n" +
                            "\"MAKERCODE\": \"" + gSmap.get("MAKERCODE") + "\",\n" +
                            "\"OPERATORCODE \": \"" + gSmap.get("OPERATORCODE") + "\",\n" +
                            "\"SECRETLEVEL\": \"" + gSmap.get("SECRETLEVEL") + "\",\n" +
                            "\"APPROVERCODE\": \"" + gSmap.get("APPROVERCODE") + "\",\n" +
                            "\"AUDITORCODE\": \"" + gSmap.get("AUDITORCODE") + "\",\n" +
                            "\"BOOKERCODE\": \"" + gSmap.get("BOOKERCODE") + "\",\n" +
                            "\"CASHIERCODE\": \"" + gSmap.get("CASHIERCODE") + "\",\n" +
                            "\"ACCMANAGERCODE\": \"" + gSmap.get("ACCMANAGERCODE") + "\",\n" +
                            "\"ISAUDIT\": \"" + gSmap.get("ISAUDIT") + "\",\n" +
                            "\"ISBOOK\": \"" + gSmap.get("ISBOOK") + "\",\n" +
                            "\"ISVOID\": \"" + gSmap.get("ISVOID") + "\",\n" +
                            "\"ISAPPROVED\": \"" + gSmap.get("ISAPPROVED") + "\",\n" +
                            "\"EXTERNALDOC\": \"" + gSmap.get("EXTERNALDOC") + "\",\n" +
                            "\"ISREADYONLY\": \"" + gSmap.get("ISREADYONLY") + "\",\n" +
                            "\"CREATOR\": \"" + gSmap.get("CREATOR") + "\",\n" +
                            "\"CREATETIME\": \"" + gSmap.get("CREATETIME") + "\",\n" +
                            "\"LASTMODIFIER\": \"" + gSmap.get("LASTMODIFIER") + "\",\n" +
                            "\"LASTMODIFIEDTIME\": \"" + gSmap.get("LASTMODIFIEDTIME") + "\",\n" +
                            "\"SUMMARY\": \"" + gSmap.get("SUMMARY") + "\",\n" +
                            "\"ACCENTRYCODE\": \"" + gSmap.get("ACCENTRYCODE") + "\",\n" +
                            "\"ACCTITLECODE\": \"" + gSmap.get("ACCTITLECODE") + "\",\n" +
                            "\"DOCENTRYAMOUNT\": " + gSmap.get("DOCENTRYAMOUNT") + ",\n" +
                            "\"LENDINGDIRECTION\": \"" + gSmap.get("LENDINGDIRECTION") + "\",\n" +
                            "\"DEPTID\": \"" + DEPTID + "\",\n" +
                            "\"RELATEDORGID\": \"" + RELATEDORGID + "\",\n" +
                            "\"ACCEMPLOYEEID\": \"" + ACCEMPLOYEEID + "\",\n" +
                            "\"FOREIGNCURRENCYID\": \"" + gSmap.get("FOREIGNCURRENCYID") + "\",\n" +
                            "\"QUANTITY\": " + gSmap.get("QUANTITY") + ",\n" +
                            "\"UNITPRICE\": " + gSmap.get("UNITPRICE") + ",\n" +
                            "\"FOREIGNCURRENCY\": " + gSmap.get("FOREIGNCURRENCY") + ",\n" +
                            "\"EXCHANGERATE\": " + gSmap.get("EXCHANGERATE") + ",\n" +
                            "\"ANCILLARYAMOUNT\": " + gSmap.get("ANCILLARYAMOUNT") + ",\n" +
                            "\"BIZDATE\": \"" + gSmap.get("BIZDATE") + "\",\n" +
                            "\"BIZCODE\": \"" + gSmap.get("BIZCODE") + "\",\n" +
                            "\"SETTLEMENT\": \"" + gSmap.get("SETTLEMENT") + "\",\n" +
                            "\"APPLICATION\": \"" + gSmap.get("APPLICATION") + "\",\n";
                    //根据辅助核算判断
                    for (int z = 1; z < 100; z++) {
                        if (fzQuery.size() > 0) {
                            for (Map<String, Object> fzmap : fzQuery) {
                                //根据查询的数据进行判断  gl_docfree1表 F1-F30
                                if(z<=60){
                                    for (Map.Entry<String, Object> entry: fzmap.entrySet()) {
                                        String key = entry.getKey();
                                        String keyValue = (String) entry.getValue();
                                        if(key.equals("F"+z)&& keyValue != null){
                                            //根据keyValue值 ，获取数据Code
                                            String wlnumSQL = "SELECT NUM,TABLENAME,TABLEKEY,CODEKEY,NAMEKEY FROM FREEMAP WHERE gscode = '"+z+"'";
                                            List<Map<String, Object>> fzObjMap = jdbcTemplate.queryForList(wlnumSQL);
                                            if(fzObjMap.size()>0){
                                                //转换code
                                                String fzpkToCode = "SELECT " + fzObjMap.get(0).get("CODEKEY") + " AS CODE FROM " + fzObjMap.get(0).get("TABLENAME") + " WHERE " + fzObjMap.get(0).get("TABLEKEY") + " ='" + keyValue + "'";
                                                //核算核算数据编号
                                                List<Entity> FZCODE = oracleSession.query(fzpkToCode);
                                                keyValue = (String) FZCODE.get(0).get("CODE");
                                                if(z<10){
                                                    GsJson += "\"SPECATEID0"+z+"\": \"" + keyValue + "\",\n";
                                                }else{
                                                    GsJson += "\"SPECATEID"+z+"\": \"" + keyValue + "\",\n";
                                                }
                                            }else{
                                                if(z<10){
                                                    GsJson += "\"SPECATEID0"+z+"\": \"\",\n";
                                                }else{
                                                    GsJson += "\"SPECATEID"+z+"\": \"\",\n";
                                                }
                                            }
                                        }
                                    }
                                }else{
                                    GsJson += "\"SPECATEID"+z+"\": \"\",\n";
                                }
                            }
                        }else{
                            if(z<10){
                                GsJson += "\"SPECATEID0"+z+"\": \"\",\n";
                            }else{
                                GsJson += "\"SPECATEID"+z+"\": \"\",\n";
                            }
                        }
                    }
                        GsJson +="\"DATASTAUS\": \"" + gSmap.get("DATASTAUS") + "\",\n" +
                                "\"ISIMPORTED\": \"" + gSmap.get("ISIMPORTED") + "\",\n" +
                                "\"BATCHNO\": \"" + gSmap.get("BATCHNO") + "\",\n" +
                                "\"REFERENCEID\": \"" + gSmap.get("REFERENCEID") + "\",\n" +
                                "\"LYPZID\": \"" + gSmap.get("LYPZID") + "\",\n" +
                                "\"FZCODE\": \"" + gSmap.get("FZCODE") + "\"," +
                                "\"DOCENTRYAMOUNTYB\": " + gSmap.get("DOCENTRYAMOUNT") + "," +
                                "\"ISHAVEFZ\": \"" + ISHAVEFZ + "\"" +
                                "},";
                        //调用GS接口，推送给GS浪潮，获取返回值;
                        logTS = (String) gSmap.get("TS");



                }
                //去掉拼接的最后一个字符
                GsJson = GsJson.substring(0, GsJson.lastIndexOf(','));
                GsJson = GsJson.replace("null","");
                GsJson += "]";
                //推送凭证
                //1、推送凭证
                //System.out.println("凭证JSON"+GsJson);
                String gsUrl = "https://" + IP + ":" + PORT + "/api/jg/fiaccbddata/v1.0/fiaccinterface/insertPzMidTable";
                String returnMSG = HttpRequest.post(gsUrl)
                        .header("Content-Type", "application/json")
                        .header("Accept-Language", "zh-CHS")
                        .header("X-ECC-Current-Tenant", ECC)
                        .header("Authorization", Bearer).timeout(200000)
                        .body(GsJson).execute().body();
                //System.out.println("凭证返回值"+returnMSG);
                if (!returnMSG.isEmpty()) {
                    String logInsert = "";
                    JSONArray returnList = JSONArray.parseArray(returnMSG);
                    for(int y =0;y<returnList.size();y++){
                        JSONObject returnObj = returnList.getJSONObject(y);
                       // System.out.println(returnObj.get("code")+"===="+returnObj.get("msg")+"======信息=======================");
                        //成功
                        if (returnObj.get("code").equals(0) ) {
                            //System.out.println("进入成功方法");
                            //修改数据表业务推送状态，标记凭证已推送\回写推送批次
                            String gsid = (String) returnObj.get("id");
                            String msg =  (String) returnObj.get("msg");
                            //ids = ids.substring(0, ids.lastIndexOf(','));
                            String updateVoucher = "update GL_DETAIL SET PUSHSTATUS = '1', BATCHNO = '"+BATCHNO+"', RETURNMSG = '"+msg+"' WHERE ID = '"+gsid+"' ";
                            System.out.println("修改凭证数据状态"+updateVoucher);
                            int updateV = jdbcTemplate.update(updateVoucher);
                            System.out.println("执行SQL修改方法");
                            if(updateV>0){
                                msg += "-------凭证状态、批次"+BATCHNO+"=====id:"+gsid+"回写成功；";
                                System.out.println("执行SQL修改方法---成功");
                            }else{
                                msg += "-------凭证状态、批次"+BATCHNO+"=====id"+gsid+"回写失败；";
                                System.out.println("执行SQL修改方法---失败");
                            }
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "成功"+msg, GsJson, returnMSG, "", "", gsUrl, logTS);
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                            //失败
                        } else if (returnObj.get("code").equals(1) ) {
                            System.out.println("进入失败方法");
                            //写入日志表
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "失败", GsJson, returnMSG, "", "", gsUrl, logTS);
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                        }else if(returnObj.get("code")==null && ("").equals(returnObj.get("code"))){
                            System.out.println("进入异常方法");
                            //写入日志表
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常", GsJson, returnMSG, "",  "", gsUrl, logTS);
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                        }else{
                            System.out.println("进入异常其他方法");
                            //写入日志表
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常", GsJson, returnMSG, "",  "", gsUrl, logTS);
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                        }
                    }
                }else{
                    System.out.println("进入异常2方法");
                    //写入日志表
                    int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常,【"+returnMSG+"】返回值为空！！！", GsJson, returnMSG, "",  "", gsUrl, logTS);
                    if (loginsert > 0) {
                        System.out.println("日志写入成功！！");
                    } else {
                        System.out.println("日志写入失败！！");
                    }
                }
            }

        }else{
            System.out.println("暂无新数据推送");
        }

    }


}
